require('../../assets/css/reset.css')
require('../../assets/css/normalize.css')
require('../../assets/iconf/iconfont.css')
require('./exercise.less')
require('../../assets/css/basic.less')
let footer = require('../../lib/utlis/footer')
footer.footer()

let axios = require('axios')
// 获取登录时储存的用户信息
let user = JSON.parse(localStorage.getItem('login'))

// 设置axios请求头,添加token
axios.defaults.headers.authorization = "Bearer " + user.token;

let newImg = document.querySelector('.newImg')
let newTitle = document.querySelector('.newTitle')
let newText = document.querySelector('.newText')
let pectorales = document.querySelector('.pectorales')
let dahezi = document.querySelector('.dahezi')

axios.get('http://47.96.154.185:3701/api/train/courseList')
.then(function(res){
    if(res.data.errno == 0){
        // 最新课程
        let newCourse = res.data.data[0]
        newImg.src = 'http://47.96.154.185:3701' + newCourse.imgurl
        newTitle.textContent = newCourse.name
        newText.textContent = newCourse.desc.slice(0,25) + '...'
        let pectorales = res.data.data.slice(1,res.data.data.length)
        // let pectorales = res.data.data.filter(function(item,index){
        //     return index > 0 
        // })
        pectorales.forEach(function(item,index){
            let a = document.createElement('a')
            // 地址中？后面可以携带任何参数，这样不会影响跳转路径
            a.href = `./dedail.html?${item.courseId}`
            a.innerHTML = `
            <div class="pectorales" style="background:url(http://47.96.154.185:3701${item.imgurl})">
               <div>
                  <p>${item.name}</p>
                  <span>${item.desc}</span>
               </div>
            </div>
            `
            dahezi.appendChild(a)
        })
    }
})